﻿using RpcHelper;
using RpcModel.Model;

using SqlExecHelper;

using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.DAL
{
        internal class ServerClientLimitDAL : SqlBasicClass
        {
                public ServerClientLimitDAL() : base("ServerClientLimit")
                {

                }
                public void Add(ServerClientLimitData add)
                {
                        base.Insert(add);
                }
                public void Set(long id, ServerClientLimit config)
                {
                        if(!base.Update(config, "id", id))
                        {
                                throw new ErrorException ("rpc.client.limit.set.error");
                        }
                }
                public ServerClientLimitData Drop (long id)
                {
                        return base.DropOutRow<long, ServerClientLimitData> ("Id", id);
                }
                public ServerClientLimitData Get (long rpcMerId, long serverId)
                {
                        return this.GetRow<ServerClientLimitData> (new ISqlWhere[] {
                                new SqlWhere("RpcMerId", System.Data.SqlDbType.BigInt){Value=rpcMerId},
                                new SqlWhere("ServerId", System.Data.SqlDbType.BigInt){Value=serverId}
                        });
                }
                public void Clear(long serverId)
                {
                        base.Drop ("ServerId", serverId);
                }
                public long FindLimitId(long rpcMerId, long serverId)
                {
                        return this.ExecuteScalar<long>("Id",  new ISqlWhere[] {
                                new SqlWhere("RpcMerId", System.Data.SqlDbType.BigInt){Value=rpcMerId},
                                new SqlWhere("ServerId", System.Data.SqlDbType.BigInt){Value=serverId}
                        });
                }
        }
}
